<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理</title>
<block th:replace="commonBase"></block>   
</head>
<script type="text/javascript">
 /*<![CDATA[*/
	var isType = [{id:'1',text:'是'},{id:'0',text:'否'}];
	var isCType = [{id:'1',text:'菜单'},{id:'0',text:'按钮'}];
/*]]>*/
</script>	
<body>
<div class="mini-fit">
	<form id="form1" method="post">
	    <input id="id" name="id" class="mini-hidden" />
		<!-- <input id="parentId" name="parentId" class="mini-hidden" /> -->
		<input id="parentIds" name="parentIds" class="mini-hidden" />
		<input id="moduleLevel" name="moduleLevel" class="mini-hidden" />
		<div style="padding-left:11px;padding-bottom:5px;">
			<table style="table-layout:fixed;">
				<tr>
					<td>功能名称:</td>
					<td colspan="3"><input name="moduleName" class="mini-textbox" style="width:355px;"
						required="true" requiredErrorText="不可为空" emptyText="功能名称" /><span><font color="red">*</font></span>
					</td>
				</tr>
				<tr>
					<td>链接URL:</td>
					<td colspan="3"><input name="moduleLink" class="mini-textbox" style="width:355px;"  emptyText="链接URL" /><span></span>
					</td>
				</tr>
				<tr>
					<td>权限标识:</td>
					<td colspan="3"><input name="permission" class="mini-textbox" style="width:355px;"   emptyText="权限标识" /><span></span>
					</td>
				</tr>
				<tr>
					<td>上级菜单:</td>
					<td colspan="3">
						<input id="parentId" name="parentId" class="mini-treeselect"  th:attr="url=@{/module/treelist(moduleId=${moduleId},opt=${opt})}" 
						 textField="moduleName" valueField="id" parentField="parentId" expandOnLoad="true"  popupWidth="350" style="width: 355px;" />
						<!--  <input id="parentName" name="parentName" required="true" class="mini-textbox"  allowInput="false" enabled="false" style="width:355px;"/>   -->
					</td>
				</tr>
				
				<tr>
					<td>来源系统:</td>
					<td colspan="3">
						<input name="serverId" class="mini-combobox"  th:attr="url=@{/module/serverlist}"  emptyText="默认" showNullItem="true" nullItemText="默认"
						 textField="serverName" valueField="id"  expandOnLoad="true"  popupWidth="350" style="width: 355px;" />
					</td>
				</tr>
				
				<tr>
    				<td>是否菜单:</td>
    				<td colspan="3">
    					<input name="isMenu" class="mini-combobox" valueField="id" textField="text" required="true" allowInput="false" width="355px" requiredErrorText="不可为空" emptyText="请选择是否菜单" 
    					data="isCType" value="1"/><font color="red">*</font>
    				</td>
    			</tr>
				<tr>
    				<td>是否启用:</td>
    				<td colspan="3">
    					<input name="isEnable" class="mini-combobox" valueField="id" textField="text" required="true" allowInput="false" width="355px" requiredErrorText="不可为空" emptyText="请选择是否启用" 
    					data="isType" value="1"/><font color="red">*</font>
    				</td>
    			</tr>
    			<tr>
					<td>排序字段:</td>
					<td colspan="3"><input name="sort" class="mini-textbox" style="width:355px;"   emptyText="排序字段" ></input>
					</td>
				</tr>
				
				<tr>
					<td>样式:</td>
					<td colspan="3">
						<!--<input name="iconCls" class="mini-textbox" style="width:355px;"   emptyText="样式图标" ></input> -->
						
					    <input id="lookup2" name="iconCls" class="mini-lookup" style="width:355px;" 
					        textField="text" valueField="id" popupWidth="auto" emptyText="样式图标"
					        popup="#gridPanel" grid="#datagrid1"  ></input>
					     <div id="gridPanel" class="mini-panel" title="header" iconCls="icon-add" style="width:350px;height:248px;" 
						        showToolbar="true" showCloseButton="true" showHeader="false" bodyStyle="padding:0" borderStyle="border:0" >
						        <div property="toolbar" style="padding:5px;padding-left:8px;text-align:center;">   
						            <div style="float:left;padding-bottom:2px;">
						                <input id="keyText" class="mini-textbox" style="width:160px;" onenter="onSearchClick"/>
						                <a class="mini-button" onclick="onSearchClick">查询</a>
						               
						            </div>
						            <div style="float:right;padding-bottom:2px;">
						                <a class="mini-button" onclick="onCloseClick">关闭</a>
						            </div>
						            <div style="clear:both;"></div>
						        </div>
						        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="50"  onrowdblclick="rrowdblclick()"
						            borderStyle="border:0" 
						            showPager="false" virtualScroll="true" sortMode="client" sortField="id" 
						            th:attr="url=@{/common/css/icons.txt}" >
						            <div property="columns">
						                <div field="id"   width="120" headerAlign="center" align="center" allowSort="true">编码</div>    
						                <div field="text"  width="120" headerAlign="center" align="center"  allowSort="true" renderer="onOpenTRenderer">图标</div>
						            </div>
						        </div>  
						    </div>    
					     
					        
					</td>
				</tr>
				
				<tr>
					<td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
					<td colspan="3"><input name="remark" class="mini-textarea"
						style="width:355px;height: 30px;" />
					</td>
				</tr>

			</table>
		</div>
	</form>
	</div>
	<div class="mini-toolbar" style="text-align:center;height:25px;padding-top:2px;padding-bottom:8px;" 
        borderStyle="border-left:0;border-bottom:0;border-right:0;">
        <a class="mini-button" onclick="onOk" iconCls="icon-save" style="width:85px;margin-right:20px;">保存</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" onclick="onCancel" iconCls="icon-close" style="width:85px;">关闭</a>
    </div>
</body>
<script type="text/javascript">
 /*<![CDATA[*/
	mini.parse();
 
	 var grid = mini.get("datagrid1");
     var keyText = mini.get("keyText");

     grid.load();

     function onSearchClick(e) {
             var key = keyText.value;
             if (key == "") {
            	 grid.clearFilter();
             } else {
                 key = key.toLowerCase();                
                 //多条件组合过滤
                 grid.filter(function (row) {
                     //name
                     var r1 = true;
                     if (key) {
                         r1 = String(row.id).toLowerCase().indexOf(key) != -1;
                     }
                     return r1;
                 });
                 
             }
     }
     function onCloseClick(e) {
         var lookup2 = mini.get("lookup2");
         lookup2.hidePopup();
     }
     
     function onOpenTRenderer(e){
    	 return '<span style="font-size:20px;" class="'+e.value+'"></span>';
      }
     
     function rrowdblclick(){
    	 onCloseClick();
     }
 
	var action = "new";
	var form = null;
	function setData(data) {
		
		action = data.action;//获取指令，是新增 还是修改
		form = new mini.Form("#form1");//获取表单对象
		data = mini.clone(data);//获取克隆数据
	    if (action == "edit") {
	        //跨页面传递的数据对象，克隆后才可以安全使用
	        data = mini.clone(data);
	        form.setData(data.fwPlModule);
	      //  mini.get("parentName").setValue(data.parentName);
    	  //  mini.get("moduleLevel").setValue(data.moduleLevel);
		 	form.setChanged(false);
	    }else{
	    
	    	data = mini.clone(data);
    		mini.get("parentId").setValue(data.parentId);//设置parentId
    		//mini.get("parentName").setValue(data.parentName);//设计父级名称
    		//mini.get("moduleLevel").setValue(data.moduleLevel); //设置模块层级
    		//mini.get("parentIds").setValue(data.parentIds); //设置父级IDs
	    }
	}
	
	//新增模块
	function moduleAdd(json){
		$.ajax({
	        url: basePath+"module/add",
			type: 'post',
	        data: {data:json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var moduleId = message.msg;//获取权限模块ID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
	            	showMsg("模块添加成功","success",800,"center","center",closeWindow(moduleId));
	        	}else{
	        		showMsg("模块添加失败","warning",800,"center","center",closeWindow);
	        	}
	        	
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	        	 mini.unmask(document.body);
	        	 showMsg("模块添加错误","danger",800,"center","center",closeWindow);
	        }
	    });
	}
	//更新模块信息
	function moduleUpdate(json){
		$.ajax({
	        url: basePath+"module/update",
			type: 'post',
	        data: { data: json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var moduleId = message.msg;//获取权限模块ID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
        			showMsg("模块更新成功","success",800,"center","center",closeWindow(moduleId));
	        	}else{
	        		showMsg("模块更新失败","warning",800,"center","center",closeWindow);
	        	}
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	        	mini.unmask(document.body);
	            showMsg("模块更新错误","danger",800,"center","center",closeWindow);
	        }
	    });
	}
	//设置moduleLevel以及parentIds
	function setModuleLevel_Ids(){
		var tree = mini.get("parentId");	
		var selectNode = tree.getSelectedNode();//获取选中的节点
		var  moduleLevel = 0;
		var parentIds = 0;
		if(!!selectNode){
			 moduleLevel = selectNode._level+1;
			 parentIds = selectNode.parentIds +","+ selectNode.id;;
		}
		mini.get("moduleLevel").setValue(moduleLevel); //设置模块层级
		mini.get("parentIds").setValue(parentIds); //设置父级IDs
		
	}
	
	
	function saveData() {
		setModuleLevel_Ids();
	    var o = form.getData();
	    form.validate();
	    if (form.isValid() == false) return;
	    var json = mini.encode(o);
	    mini.mask({
	        el: document.body,
	        cls: 'mini-mask-loading',
	        html: '加载中...'
	    });
	    //alert(json);
	    if (action == "edit"){
	        moduleUpdate(json);
	    }else{
	    	moduleAdd(json);
	    }
	}
	
	
	function onOk(){
		saveData();
	}
	
	function closeWindow(action) {
	    if (action == "close" && form.isChanged()) {
	        if (confirm("数据被修改了，是否先保存？")) {
	            return false;
	        }
	    }
	    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	    else window.close();            
	}
	
	function onCancel(){
		closeWindow("close");
	}
/*]]>*/
</script>
</html>